package data;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import org.joda.time.DateTime;

import main.Topic;
import data.MailStat;
import data.WordParser;

public class DataManager
{
	int ONE_WEEK_MILLISECONDS = 604800000;
	int MAX_KEYWORDS = 5;
	
	//DateTime startTime;
	//DateTime endTime;
	Calendar startTimeCal;
	Calendar endTimeCal;
	ArrayList<String> labels;

	
	public DataManager(){
		WordParser.initialize();
		//startTime = MailStat.findStartDate(null);
		//endTime = MailStat.findEndDate(null);
		
		startTimeCal = new GregorianCalendar(2011, 00, 01, 0, 0);
		endTimeCal = new GregorianCalendar(2011, 11, 25, 0, 0);
	}
	
	public ArrayList<String> getLabelsForDateSelected(){
		SimpleDateFormat dateformatter = new SimpleDateFormat("MM/dd/yyyy");
	    labels = new ArrayList<String>();
		while(startTimeCal.before(endTimeCal)){
			labels.add(dateformatter.format(startTimeCal.getTime()));
			startTimeCal.add(Calendar.DAY_OF_YEAR, + 7);
		}
		return labels;
	}
	
	public Topic[] setupTopics(){
		String[] topicStrings = MailStat.getTopicsList();
		Topic[] topics = new Topic[topicStrings.length];
		
	
		for(int i = 0; i < topics.length ; i++){
			topics[i] = new Topic();
			topics[i].percents = MailStat.getYearPercents(topicStrings[i]);
			topics[i].keywords = MailStat.getKeywordList(topicStrings[i], startTimeCal, endTimeCal);
		    topics[i].label = topicStrings[i];
		}

		return topics;
	}
	
	public int[] getDataPercentages(int index){
		int[] percents = new int[labels.size()];
		return percents;
	}
	
	public String[] getKeywords(int index){
		String[] keywords = new String[MAX_KEYWORDS];
		return keywords;
	}
	
	public String getLabel(int index){
		String label = "";
		return label;
	}
	
	
	/**
	 * TESTING TESTING TESTING 
	 * NOT A REAL FUNCTION
	 * @param start
	 * @return
	 */
	public int[] setupDataPercentages(int start){
		int[] topics = new int[labels.size()];
		int percent = start;
		for(int i = 0 ; i < labels.size() ; i++){
			if(i < 50){
				topics[i] = percent;
				percent--;
			}
			if(i > 50 && i < 130){
				topics[i] = percent;
				percent++;
			}
			if(i> 130)
				topics[i] = percent;
		}
		return topics;
	}
	/**
	 * TESTING TESTING TESTING 
	 * NOT A REAL FUNCTION
	 * @param start
	 * @return
	 */
	
	public String[] setupKeyword(){
		String[] testKeyword =  {"hello", "goodbye", "ya", "cool"};
		return testKeyword;
	}
}
